package spring.proxy;

import utils.ReflectUtils;

import java.util.Objects;

public class JdkProxyFactory implements ProxyFactory {

    JdkProxyFactory() {
    }

    public <T> T create(String clsName, Class<?>... args) {
        Object object = ReflectUtils.createObject(clsName);
        if (Objects.isNull(object)) {
            throw new ProxyException("代理对象类型无效，无法创建。");
        }
        return create(object);
    }

    @Override
    public <T> T create(Object originObject, Class<?>... args) {
        //noinspection unchecked
        return (T) new JdkBeanProxy().getProxyInstance(originObject);
    }
}
